#!/usr/bin/env python
"""
Copyright (C)2010 Humanetrix Foundation, Inc.

This file is a part of the GROUP MATCH PYTHON. GROUP MATCH PYTHON is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses>.

About this Project
------------------
GROUP MATCH PYTHON was the outcome of Dev Derby (http://devderby.com), held in Bloomington, Indiana on September 11, 2010. The challenge was to build a system to allow groups to offer services to non-profits and manage feedback on prior volunteer efforts, initiating the flow of quality human resources to the organizations that need them. This had to be done in one six-hour session.

Five teams representing different programming languages competed in this first event. Team Python includes:

	Charles Brandt, Team Lead 
	Rajesh Gollapudi 
	Vijay Lulla 
	Josh Dolitsky

Questions or comments should be directed to info@devderby.com.
"""

import cgi
import datetime
import wsgiref.handlers

from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp

from models import *
from models.volunteer import *
from models.group import *
from models.volunteergroup import *
from models.opportunity import *
from models.skills import *


class MainPage(webapp.RequestHandler):
  def get(self):
    user = users.get_current_user()
    if user: 
      
      self.response.out.write("""
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Volunteer Network - User Profile</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/reset.css"/>
        <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.4.custom.css"/>
        <link rel="stylesheet" type="text/css" href="css/malo.css"/>
        <style type="text/css" media="screen"> 
            @import url('http://bloomington.in.gov/skins/cob/screen.css');
        </style> 
        <style type="text/css" media="print"> 
            @import url('http://bloomington.in.gov/skins/cob/print.css');
        </style> 
        <link rel="stylesheet" type="text/css" href="css/jquery.ui.stars.min.css"/>
        <link rel="stylesheet" type="text/css" href="css/forms.css"/>
        <link rel="stylesheet" type="text/css" href="css/site.css"/>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
        <script type="text/javascript" src="js/jquery.ui.stars.min.js"></script>
        <script type="text/javascript" src="js/site.js"></script>
    </head>
    <body>
        <div id="banner"> 
            <div id="logo"><a href="http://bloomington.in.gov/">City of Bloomington, IN</a></div> 
            <div id="skipNavigation"><a href="#mainContent" title="Skip Navigation">Skip Navigation</a></div> 
            <div class="widgets"> 

                <div class="widget take-action"> 
                    <h1>Take Action</h1> 
                    <ul> 
                        <li class="do"><a href="http://bloomington.in.gov/facets/viewFacet.php?facet_id=10">Do</a></li> 
                        <li class="report"><a href="http://bloomington.in.gov/facets/viewFacet.php?facet_id=13">Report</a></li> 
                        <li class="ask"><a href="http://bloomington.in.gov/facets/viewFacet.php?facet_id=12">Ask</a></li> 
                        <li class="explore"><a href="http://bloomington.in.gov/facets/viewFacet.php?facet_id=29">Explore</a></li> 

                    </ul> 
                </div> 
            </div> 
            <div id="mainLinks"> 
                <ul><li class="first"><a href="http://bloomington.in.gov/documentTypes/documents.php?documentType_id=4">Services</a></li> 
                    <li><a href="http://bloomington.in.gov/documentTypes/documents.php?documentType_id=5">News</a></li> 
                    <li><a href="http://bloomington.in.gov/calendars">Calendars</a></li> 
                    <li><a href="http://bloomington.in.gov/locations">Locations</a></li> 
                    <li><a href="http://bloomington.in.gov/mybloomington">myBloomington</a></li> 
                    <li><a href="http://bloomington.in.gov/search/sitemap.php">Sitemap</a></li> 
                </ul> 
            </div> 
            <div id="secondaryLinks"> 
                <ul><li class="first"><a href="http://bloomington.in.gov/subscribe">Subscribe</a></li> 
                    <li><a href="http://bloomington.in.gov/contact">Contact Us</a></li> 
                    <li><form method="get" action="http://bloomington.in.gov/search"> 
                            <fieldset><legend>Search</legend> 
                                <input name="search" size="60" value="" /> 
                                <button type="submit" class="search">Search</button> 
                            </fieldset> 
                        </form> 
                    </li> 
                </ul> 
            </div> 
        </div> 
        <div id="topLevelSections"> 
            <ul><li class="home"><a href="http://bloomington.in.gov">Home</a></li> 
                <li class="government"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=4">Government</a></li> 
                <li class="community"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=5">Community</a></li> 
                <li class="business-sustainability"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=6">Business &amp; Sustainability</a></li> 
                <li class="arts-culture"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=218">Arts &amp; Culture</a></li> 
                <li class="parks-recreation"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=8">Parks &amp; Recreation</a></li> 
                <li class="public-safety"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=3">Public Safety</a></li> 
                <li class="transportation"><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=10">Transportation</a></li> 
            </ul> 
        </div> 
        <div id="main-content-container" class="dp100"> 
            <div id="mainContent2"  xml:lang="en" lang="en" > 

                <div id="pageTitle"> 
                    <div class="breadcrumbs"> 
                        <ul> 
                            <li><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=1">Home</a></li> 
                            <li><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=5">Community</a></li> 
                            <li><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=455">Volunteering &amp; Community Involvement</a></li> 
                            <li><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=181">Volunteer Network</a></li> 
                            <li><a href="http://bloomington.in.gov/sections/viewSection.php?section_id=295">About the Volunteer Network</a></li> 

                        </ul> 
                    </div> 

                    <h1>About the City of Bloomington Volunteer Network</h1> 
                </div> 
                <div class="demo" style="margin-bottom: 20px; padding-bottom: 20px;">
                    <h2> User Home</h2>
                    <p>   Welcome, DevDerby. Please find below a list of opportunities to volunteer. </p>

                    <div class="dp20">
                        <a class="left_sidebar_link" href="">Add availability</a> 
                        <a class="left_sidebar_link" href="">Profile</a>
                    </div>
                    <div class="dp80">
                        <div style="padding: 0 10px;">
                            <table>
                                <tr>
                                    <th>Time</th>
                                    <th>Matching opportunities
                                </tr>
                                <tr>
                                    <td>Opportunity1</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>
                                <tr>
                                    <td>Opportunity2</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>
                                <tr>
                                    <td>Opportunity3</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>

                            </table>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <hr/>
                    <h2> Non Profit Home</h2>
                    <p> Welcome, DevDerby Non-profit. Please find below a list of volunteers that might match your criterion. </p>

                    <div class="dp20">
                        <a class="left_sidebar_link" href="">Add Opportunity</a>
                        <a class="left_sidebar_link" href="">Profile</a>
                    </div>
                    <div class="dp80">
                        <div style="padding: 0 10px;">
                            <table>
                                <tr>
                                    <th>Time</th>
                                    <th>Matching opportunities
                                </tr>
                                <tr>
                                    <td>Opportunity1</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>
                                <tr>
                                    <td>Opportunity2</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>
                                <tr>
                                    <td>Opportunity3</td>
                                    <td>Event1<br>Event2<br/></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div><!-- End demo -->
            </div>
        </div>
        <div id="footer">
            <div>
                <ul>

                    <li class="first"><a href="http://bloomington.in.gov/login">Sign In</a></li>
                    <li><a href="http://bloomington.in.gov/documents/az_index.php">A-Z Index</a></li>
                    <li><a href="http://bloomington.in.gov/website-privacy-statement">Privacy</a></li>
                    <li><a href="http://bloomington.in.gov/Website-Accessibility-Statement">Accessibility</a></li>
                    <li><a href="http://bloomington.in.gov/languages">Languages</a></li>
                    <li><a href="http://bloomington.in.gov/feeds">Feeds</a></li>
                    <li><a href="http://bloomington.in.gov/jobs">Jobs</a></li>
                    <li><a href="http://bloomington.in.gov/search/sitemap.php">Sitemap</a></li>
                </ul>

            </div>
        </div>
    </body>
</html>
""")
    else:
      self.response.out.write('<html><body>')
      self.response.out.write('<a href="%s">Create or Sign in</a>' % (users.create_login_url("/"),))
      self.response.out.write('</body></html>')
      # self.response.out.write("<html><body>")
      # self.response.out.write("Need login....redirect to login page.\n")
      # self.response.out.write("</body></html>")


    # self.response.out.write('<html><body>')
    # self.response.out.write('hello world')
    # self.response.out.write('</body></html>')

    # volunteers = db.GqlQuery("SELECT * "
    #                       "FROM Volunteer "
    #                       "ORDER BY created DESC LIMIT 10")

    # self.response.out.write('Volunteers:<br>')
    # self.response.out.write("found: %s" % volunteers.count())
    # for volunteer in volunteers:
    #   #if volunteer.creator:
    #   #  self.response.out.write('<b>%s</b> wrote:' % volunteer.author.nickname())
    #   #else:
    #   #  self.response.out.write('An anonymous person wrote:')
    #   self.response.out.write('----:')
    #   self.response.out.write('<blockquote>%s</blockquote>' %
    #                           cgi.escape(volunteer.name))

    # self.response.out.write("""
    #       <form action="/volunteer/new" method="post">
    #         <div><textarea name="content" rows="3" cols="60"></textarea></div>
    #         <div><input type="submit" value="Add Volunteer"></div>
    #       </form>
    #     </body>
    #   </html>""")


application = webapp.WSGIApplication([
  ('/', MainPage),
  ('/volunteer/', ListVolunteer),
  ('/volunteer/new', NewVolunteer),
  ('/group/', ListGroup),
  ('/group/new', NewGroup),
  ('/skill/', ListSkill),
  ('/skill/new', NewSkill),
], debug=True)


def main():
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
  main()
